package van.planifolia.stream;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

/**
 * Created by Intellij IDEA<br>
 *
 * @author Planifolia.Van
 * @version 1.0
 * @date 2022/11/4 18:52
 */
public class StreamDemo1 {
    public static void main(String[] args) {
        List<People> peoples = new ArrayList<>();
        peoples.add(new People("刘星", 18, "米国"));
        peoples.add(new People("刘赞", 16, "中国"));
        peoples.add(new People("王星", 21, "俄国"));
        peoples.add(new People("赵星", 46, "法国"));
        peoples.add(new People("刘参", 33, "中国"));
        peoples.add(new People("刘忙", 19, "霓虹国"));
        peoples.add(new People("刘参宿", 24, "中国"));
        // 演示常用的api方法
        peoples .stream()
                // 过滤大于18的
                .filter(people -> people.getAge() > 18)
                // 按照年龄排序
                .sorted(Comparator.comparingInt(People::getAge))
                // 修改地址为中国
                .peek(people -> people.setAddress("中国"))
                // 只取三人
                .limit(3)
                // 便利循环
                .forEach(System.out::println);
    }
}
